package yanchun.vip.spring.ioc.model.po;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.Data;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author SuYanchun
 * @since 2025-02-10 09:15
 */
@Data
public class User implements InitializingBean, DisposableBean{

    private String name;

    private Integer age;

    private Integer gender;


    private Car car;

    @Autowired
    public void setCar(Car car) {
        this.car = car;
        System.out.println("组件设置，注入属性");
    }

    private void init(){
        System.out.println("User组件指定初始化方法");
    }

    private void destroyUser(){
        System.out.println("User组件指定销毁方法");
    }

    public User() {
        System.out.println("构造器执行");
    }


    /**
     * 属性设置之后调用
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("【InitializingBean】—— afterPropertiesSet方法");
    }


    /**
     * 指定容器方法销毁之前调用
     * @throws Exception
     */
    @Override
    public void destroy() throws Exception {
        System.out.println("【DisposableBean】—— destroy方法");
    }

    /**
     * 销毁前置处理钩子
     */
    @PostConstruct
    public void postConstruct(){
        System.out.println("【@PostConstruct】—— postConstruct方法");
    }

    /**
     * 构造器后置处理钩子
     */
    @PreDestroy
    public void preDestroy(){
        System.out.println("【@PreDestroy】—— preDestroy方法");
    }

}
